#include <QMenu>
#include <QMenuBar>
#include <QTabWidget>
#include <QWidget>
#include <QIcon>
#include <QToolBar>
#include <QCoreApplication>

#include "MainWindow.h"
#include "XmlFile.h"
#include "Section.h"

MainWindow::MainWindow()
{
    setMinimumSize(800, 600);
    setWindowTitle("GAD V0.1 Configuration File Generator for Actuator Diagnostic");

    m_menuFile = menuBar()->addMenu("&File");			// Menu 'File'
    m_sheetNewProject = m_menuFile->addMenu("New");			// Sous-Menu 'New'
    m_sheetNewProject->addAction("Project");					// 'New Project'

    m_sheetOpenProject = m_menuFile->addMenu("Open");		// Sous-Menu 'Open'
    m_sheetOpenProject->addAction("Project");					// 'Open Project'

    m_actionSave = m_menuFile->addAction("&Save");			// Sous-menu 'Save'
    m_actionSave->setShortcut(QKeySequence("Ctrl+S"));                // Raccourci
    m_actionSave->setIcon(QIcon(QCoreApplication::applicationDirPath() + "/save1.png"));
    m_actionSaveAs = m_menuFile->addAction("&Save As ..."); // Sous-menu 'Save As'
    m_actionGenerate = m_menuFile->addAction("&Generate Xml File");// Sous-menu 'Generate Xml File'
    m_actionGenerate->setIcon(QIcon(QCoreApplication::applicationDirPath() + "/export1.png"));

    m_actionGenerate->setShortcut(QKeySequence("Ctrl+G"));
    m_actionExit = m_menuFile->addAction("&Exit");			// Sous-menu 'Exit'
    m_actionExit->setShortcut(QKeySequence("Ctrl+Q"));
    m_actionExit->setIcon(QIcon(QCoreApplication::applicationDirPath() + "/exit1.png"));

    m_menuEdit = menuBar()->addMenu("&Edit");			// Menu 'Edit'
    m_sheetNew = m_menuEdit->addMenu("New");
    m_actionAddSection = m_sheetNew->addAction("Section");		// 'New Section'
    m_actionAddSection->setIcon(QIcon(QCoreApplication::applicationDirPath() + "/addsection1.png"));
    m_actionAddData = m_sheetNew->addAction("Data");		// 'New Data'
    m_actionAddData->setIcon(QIcon(QCoreApplication::applicationDirPath() + "/adddata1.png"));

    m_sheetDelete = m_menuEdit->addMenu("Delete");     // Sous menu 'Delete'
    m_actionDeleteSection = m_sheetDelete->addAction("Section");
    m_actionDeleteSection->setIcon(QIcon(QCoreApplication::applicationDirPath() + "/delsection1.png"));
    m_actionDeleteData = m_sheetDelete->addAction("Data");
    m_actionDeleteData->setIcon(QIcon(QCoreApplication::applicationDirPath() + "/deldata1.png"));

    m_menuHelp = menuBar()->addMenu("&Help");			// Menu 'Help'
    m_actionAbout = m_menuHelp->addAction("&About CDG");		// Sous-Menu 'About CDG'
    m_actionAbout->setShortcut(QKeySequence("Ctrl+H"));
    m_actionAbout->setIcon(QIcon(QCoreApplication::applicationDirPath() + "/help1.png"));

    //new XmlFile();
    m_section = new Section(this);

    QToolBar *toolBar = addToolBar("File");
    toolBar->addAction(m_actionExit);
    toolBar->addSeparator();
    toolBar->addAction(m_actionSave);
    toolBar->addSeparator();
    toolBar->addAction(m_actionAddSection);
    toolBar->addAction(m_actionDeleteSection);
    toolBar->addSeparator();
    toolBar->addAction(m_actionAddData);
    toolBar->addAction(m_actionDeleteData);
    toolBar->addSeparator();
    toolBar->addAction(m_actionGenerate);
    toolBar->addSeparator();
    toolBar->addAction(m_actionAbout);

    // Connections
    connect(m_actionExit, SIGNAL(triggered()), qApp, SLOT(quit()));	// Quitter l'application
    connect(m_actionAddSection, SIGNAL(triggered()), m_section, SLOT(addSection()));          // Ajouter Section
    connect(m_actionDeleteSection, SIGNAL(triggered()), m_section, SLOT(deleteSection()));    // Supprimer Section
    connect(m_actionGenerate, SIGNAL(triggered()), this, SLOT(generateXmlFile()));            // Generate file
    connect(m_actionAddData, SIGNAL(triggered()), m_section, SLOT(addData()));
}

void MainWindow::generateXmlFile()
{
    XmlFile file;
    file.save();
}





